package com.ruoyi.produce.base.mrp.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.produce.base.bom.domain.Bom;
import com.ruoyi.produce.base.mrp.domain.MRP;
import com.ruoyi.produce.base.mrp.service.IMRPService;
import com.ruoyi.produce.process.planself.domain.ProducePlanSelfCond;
import com.ruoyi.produce.process.planself.domain.ProducePlanSelfDto;
import com.ruoyi.psi.sale.order.domain.SaleOrderCond;
import com.ruoyi.psi.sale.order.domain.SaleOrderListDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * MRP运算
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/produce/mrp")
public class MRPController extends BaseController {
    @Autowired
    private IMRPService mrpService;

    /**
     * 获取生产计划
     * @param cond
     * @return
     */
    @PostMapping("/selectProducePlanSelf")
    public TableDataInfo selectProducePlanSelf(@RequestBody ProducePlanSelfCond cond){
        startPage();
        return getDataTable(mrpService.selectProducePlanSelf(cond));
    }
    /**
     * 通过MRP生成产品毛需求
     * @param producePlanSelf
     * @return
     */
    @PostMapping("/selectDemandListByProducePlanSelf")
    public AjaxResult selectDemandListByProducePlanSelf(@RequestBody ProducePlanSelfDto producePlanSelf){

        return AjaxResult.success(mrpService.selectDemandListByProducePlanSelf(producePlanSelf));
    }

    /**
     * 通过MRP获取销售订单
     * @param cond
     * @return
     */
    @PostMapping("/selectSaleOrderList")
    public TableDataInfo selectSaleOrderList(@RequestBody SaleOrderCond cond){
        startPage();
        return getDataTable(mrpService.selectSaleOrderList(cond));
    }

    /**
     * 销售产品通过MRP生成产品毛需求
     * @param saleOrderList
     * @return
     */
    @PostMapping("/selectDemandListBySaleOrderList")
    public AjaxResult selectDemandListBySaleOrderList(@RequestBody SaleOrderListDto saleOrderList){

        return AjaxResult.success(mrpService.selectDemandListBySaleOrderList(saleOrderList));
    }

    /**
     * 毛需求通过MRP生成产品自产计划建议，产品采购建议
     * @param bom 毛需求
     * @return
     */
    @PostMapping("/getAdvise")
    public AjaxResult getAdvise(@RequestBody Bom bom){
        return AjaxResult.success(mrpService.getAdviseByDemandList(bom));
    }


    /**
     * 根据自产计划建议，生成生产计划
     * @param mrps 自产计划建议
     * @return
     */
    @PostMapping("/releaseProducePlanSelf")
    public AjaxResult releaseProducePlanSelf (@RequestBody List<MRP> mrps){
        return toAjax(mrpService.releaseProducePlanSelf(mrps));
    }
    /**
     * 根据自产计划建议，生成生产计划
     * @param mrps 自产计划建议
     * @return
     */
    @PostMapping("/releasePurchaseApply")
    public AjaxResult releasePurchaseApply (@RequestBody List<MRP> mrps){
        return toAjax(mrpService.releasePurchaseApply(mrps));
    }

    /**
     * 更新毛需求表
     * @param bom
     * @return
     */
    @PostMapping("/updateDemandList")
    public AjaxResult updateDemandList(@RequestBody Bom bom) {
        return toAjax(mrpService.updateDemandList(bom));
    }
}
